; -*- Midas -*-
;;; Copyright (c) 1999 Massachusetts Institute of Technology
;;;
;;; This program is free software; you can redistribute it and/or
;;; modify it under the terms of the GNU General Public License as
;;; published by the Free Software Foundation; either version 3 of the
;;; License, or (at your option) any later version.
;;;
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;;; General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with this program; if not, see https://gnu.org/licenses or
;;; write to:
;;;  Free Software Foundatiom, Inc.
;;;  51 Franklin St, Fifth Floor
;;;  Boston, MA 02110-1301
;;;  USA

.AUXIL

; Canonical symbol definition macro, FOO==BAR with error check.
IFNDEF DEFSYM,[	
DEFINE DEFSYM X/
IRPS Z,,[X]
IFNDEF Z,X
.ELSE [	$$TEM1==Z
	X
	IFN Z-$$TEM1,.ERR Z MULTIPLY .QUOTE`.QUOTE/DEFINED/`
      ]
.ISTOP
TERMIN TERMIN
$$TEMP==1
] ;IFNDEF DEFSYM
.ELSE, $$TEMP==0

; For now, must have a disk type defined to get the correct register
; definitions. 

IFNDEF RP06P,RP06P==0
IFNDEF RP07P,RP07P==0
IFNDEF RM03P,RM03P==0
IFNDEF RM80P,RM80P==0

IFN RP06P+RP07P+RM03P+RM80P-1,.FATAL Only one disk type allowed in RH11 DEFS


;;; Disk RH11 Interrupt vector:
DEFSYM	PHVEC==254		; Interrupts occur on level 6
				; (high priority) on UBA #1.

;;; Disk RH11 Unibus register addresses:

DEFSYM	%HRCS1=:776700		;CTRL AND STATUS 1.
 DEFSYM	%HXSC==	1_15.		; Special Condition
 DEFSYM	%HXTRE==1_14.		; Transfer Error
 DEFSYM	%HXMCP==1_13.		; Mass I/O Control Bus Parity Error
 DEFSYM	%HXDVA==1_11.		; Drive Available
 DEFSYM	%HXPSE==1_10.		; Port Select
 DEFSYM	%HXA17==1_9.		; UB Address Extension Bit 17
 DEFSYM	%HXA16==1_8.		; UB Address Extension Bit 16
 DEFSYM	%HXRDY==1_7.		; Ready
 DEFSYM	%HXIE==	1_6.		; Interrupt Enable
 DEFSYM	$HXCMD==.BP 77		; Bits 1-5 specify commands.
 DEFSYM	%HXGO==	1_0.		; GO bit

;;; Commands with bit 0 (GO) included:

DEFSYM	%HMNOP==0	; No Operation
DEFSYM	%HMUNL==3	; Unload ("Standby" --  the pack doesn't fly off).
DEFSYM	%HMREC==7	; Recalibrate
DEFSYM	%HMCLR==11	; Drive clear (reset errors etc.)
DEFSYM	%HMRLS==13	; Drive release (dual port)
DEFSYM	%HMSRC==31	; Search (for r.p.s.)
DEFSYM	%HMWCH==51	; Write Check (?doesn't work)
DEFSYM	%HMWCF==53	; Write Check Format, Header and Data (?doesn't work)
DEFSYM	%HMWRT==61	; Write Data
DEFSYM	%HMRED==71	; Read Data
DEFSYM	%HMWHD==63	; Write Header And Data (format the pack)
DEFSYM	%HMRHD==73	; Read Header and Data
IFN RP07P,[
DEFSYM	%HMWTD==65	; Write Track Descriptor
DEFSYM	%HMRTD==75	; Read Track Descriptor
]
DEFSYM	%HMSEK==5	; Seek to Cylinder
DEFSYM	%HMOFS==15	; Offset Heads Slightly
			; Just sets %HSOFS on RP07
DEFSYM	%HMCEN==17	; Return Heads To Centerline
			; Just clears %HSOFS on RP07
DEFSYM	%HMACK==23	; Acknowledge mounting of pack (required before I/O)
			; No-op on RP07
DEFSYM	%HMRDP==21	; Read-In Preset

DEFSYM	%HRWC=:776702		;WORD COUNT.

DEFSYM	%HRBA=:776704		;UNIBUS ADDRESS.

DEFSYM	%HRADR=:776706		;DESIRED ADDRESS.
  DEFSYM	$HATRK==.BP 37400  	; Track
  DEFSYM	$HASEC==.BP 00177	; Sector
  ;; These are the sizes on the RP07 -- other drives are smaller.
  ;; This is OK, as most places calculate this as Track_8+Sector

DEFSYM	%HRCS2=:776710		;CTRL AND STATUS 2.
 DEFSYM	%HYDLT==1_15.		; Data Late
 DEFSYM	%HYWCE==1_14.		; Write Check Error
 DEFSYM	%HYPE==	1_13.		; Parity Error
 DEFSYM	%HYNED==1_12.		; Non-existant Drive
 DEFSYM	%HYNEM==1_11.		; %HRBA is NXM during DMA
 DEFSYM	%HYPGE==1_10.		; Program Error
 DEFSYM	%HYMXF==1_9.		; Missed Transfer
 DEFSYM	%HYMDP==1_8.		; Mass Data Bus Parity Error
 DEFSYM	%HYOR==	1_7.		; Output Ready (for Silo buffer diag.)
 DEFSYM	%HYIR==	1_6.		; Input  Ready (for Silo buffer diag.)
 DEFSYM	%HYCLR==1_5.		; Controller Clear
 DEFSYM	%HYPAT==1_4.		; Parity Test
 DEFSYM	%HYBAI==1_3.		; Unibus Address Increment Inhibit
 DEFSYM	$HYDSK==.BP 7		; Bits 2-0 are the Unit Select.

DEFSYM	%HRSTS=:776712		;DRIVE STATUS.
 DEFSYM	%HSATN==1_15.		; Attention Active
 DEFSYM	%HSERR==1_14.		; Error
 DEFSYM	%HSPIP==1_13.		; Positioning In Progress
 DEFSYM	%HSMOL==1_12.		; Medium On-Line
 DEFSYM	%HSWRL==1_11.		; Write Locked
 DEFSYM	%HSLST==1_10.		; Last Sector Transferred
 DEFSYM	%HSPGM==1_9.		; Programmable
 DEFSYM	%HSDPR==1_8.		; Drive Present
 DEFSYM	%HSRDY==1_7.		; Drive Ready
 DEFSYM	%HSVV==	1_6.		; Volume Valid
; These are RP04-only bits in %HRSTS
; DEFSYM	%HSDE1==1_5.		; Difference Equals 1
; DEFSYM	%HSL64==1_4.		; Difference Less Than 64
; DEFSYM	%HSGRV==1_3.		; Go Reverse
; DEFSYM	%HSDIG==1_2.		; Drive To Inner Guard Band
; DEFSYM	%HSF20==1_1.		; Drive Forward 20in/sec
; DEFSYM	%HSF5==	1_0.		; Drive Forward 5in/sec
IFN RP07P,[
 DEFSYM %HSILS==1_2.		; Interleaved Sectors
 DEFSYM %HSWRN==1_1.		; Early Warning
 DEFSYM %HSOFS==1_0.		; Offset Mode
]

DEFSYM	%HRER1=:776714		;ERROR 1.
 DEFSYM	%H1ECC==1_15.		; Data Check
 DEFSYM	%H1UNS==1_14.		; Unsafe
 DEFSYM	%H1OPI==1_13.		; Operation Incomplete
 DEFSYM	%H1DTE==1_12.		; Drive Timing Error
 DEFSYM	%H1WLK==1_11.		; Write Lock Error
 DEFSYM	%H1IAE==1_10.		; Invalid Address Error
 DEFSYM	%H1AOE==1_9.		; Address Overflow Error
 DEFSYM	%H1CRC==1_8.		; Header CRC Error
 DEFSYM	%H1HCE==1_7.		; Header Compare Error
 DEFSYM	%H1ECH==1_6.		; ECC Hard Error
 DEFSYM	%H1WCF==1_5.		; Write Clock Fail
 DEFSYM	%H1FER==1_4.		; Format Error
 DEFSYM	%H1PAR==1_3.		; Parity Error
 DEFSYM	%H1RMR==1_2.		; Register Modification Refused
 DEFSYM	%H1ILR==1_1.		; Illegal Register
 DEFSYM	%H1ILF==1_0.		; Illegal Function

DEFSYM	%HRATN=:776716		;ATTENTION SUMMARY.
	; Each bit 7-0 corresponds to a drive asserting ATA.

DEFSYM	%HRLAH=:776720		;LOOK AHEAD.
				; 2.2 - 1.7  Sector Count.
				; 1.6 - 1.5  Encoded Extension Field.

DEFSYM	%HRBUF=:776722		;DATA BUFFER.

DEFSYM	%HRMNT=:776724		;MAINTENANCE.

DEFSYM	%HRTYP=:776726		;DRIVE TYPE.
				; 2.7  NOT BLOCK ADDRESSED
				; 2.6  TAPE
				; 2.5  Moving Head (better be a 1!!)
				; 2.3  Drive Request Required
				; 1.9 - 1.1  Drive Type Number:
				;  RP04 = 20, RP05 = 21,
				;  RP06 = 22, RM03 = 24,
				;  RM80 = 26, RP07 = 42

DEFSYM	%HRSER=:776730		;SERIAL NUMBER.

DEFSYM	%HROFS=:776732		;OFFSET.
				; 2.9-2.8 Unused
				; 2.7  Sign Change (RP06 only)
				; 2.7  Command Modifier (RP07 only)
				;  Must be set before %HMWHD, %HMWTD or %HMRTD
				; 2.6  Move Track Descriptor (RP07 only)
				;  0 = 128. bit track descriptor
				;  1 = 344. bit track descriptor
				; 2.4  Format Bit (1=16, 0=18)
				; 2.3  ECC Inhibit
				; 2.2  Header Compare Inhibit
				; 2.1  Skip Sector Inhibit (RM 16bit only)
				; 1.9  Unused
				; 
				; 1.8 - 1.1  Unused on RP07 
				;  RP07 doesn't support offsets
				; 
				; RP06 Offsets
				; 1.8 - 1.1  Offset Info
				;   +400  u"   00010000
				;   -400  u"   10010000
				;   +800  u"   00100000
				;   -800  u"   10100000
				;   +1200 u"   00110000
				;   -1200 u"   10110000
				;   Centerline 00000000
				;
				; RMxx Offsets
				; 1.1-1.7  Unused
				; 1.8  Offset Direction
				;   0 - Away from spindle
				;   1 - Towards spindle

DEFSYM	%HRCYL=:776734		;DESIRED CYLINDER.

IFN RP06P,[

DEFSYM	%HRCCY=:776736		;CURRENT CYLINDER.

DEFSYM	%HRER2=:776740		;ERROR 2.
 DEFSYM %H2NHS==1_10.		; No Head Selection
 DEFSYM %H2WRU==1_8.		; Write Ready Unsafe

DEFSYM	%HRER3=:776742		;ERROR 3.
 DEFSYM %H3OFC==1_15.		; Off Cylinder
 DEFSYM	%H3SKI==1_14.		; Seek Incomplete (also sets UNS+ATA+PIP+RDY)
 DEFSYM %H3DCL==1_6.		; DC power low (or perhaps AC?)
 DEFSYM %H3ACL==1_5.		; AC power low (or perhaps DC?)
				; (the documentation is confused about
				; which is which.)

];RP06P

IFN RP07P,[

DEFSYM	%HRCCY=:776736		;CURRENT CYLINDER.

DEFSYM	%HRER2=:776740		;ERROR 2.
 DEFSYM %H2PRG==1_15.		; Program Error
 DEFSYM %H2CRM==1_14.		; Control ROM parity error
 DEFSYM %H2H88==1_13.		; 8080 in drive is hung
 ;; DEC unimaginatively calls the following three bits
 ;; READ/WRITE UNSAFE 1, 2 and 3.
 DEFSYM %H2WU3==1_12.		; Write current when no write in progress
 DEFSYM %H2WU2==1_11.		; More than one head selected
 DEFSYM %H2WU1==1_10.		; No write transitions during a write
 DEFSYM %H2WOV==1_9.		; Write Overrun
 DEFSYM %H2WRU==1_8.		; Write Ready Unsafe
 DEFSYM $H2COD==.BP 377		; Error Code
 ;; Error codes are:
 ;; 012 Seek operation too long.
 ;; 013 Guard band detected during seek operation.
 ;; 014 Seek operation overshoot.
 ;; 104 Guard band detection failure during recalibrate operation.
 ;; 105 Reference gap or guard band pattern detection failure during
 ;;	recalibrate operation.
 ;; 106 Seek error during recalibrate operation.
 ;; 112 Heads have attempted to land on guard band during recalibrate
 ;;	operation.

DEFSYM	%HRER3=:776742		;ERROR 3.
 DEFSYM %H3BDS==1_15.		; Bad Sector
 DEFSYM	%H3SKI==1_14.		; Seek Incomplete (see error code in ER2)
 DEFSYM %H3DSE==1_13.		; Defect Skip Error
 DEFSYM %H3WCF==1_12.		; Write Current Failure
 DEFSYM %H3LCF==1_11.		; Logic Control Failure
 DEFSYM %H3LBC==1_10.		; Loss of Bit Clock
 DEFSYM %H3LCE==1_9.		; Loss of Cylinder Error
 DEFSYM %H3X88==1_8.		; 8080 in drive failed to respond to a command
 DEFSYM %H3DCK==1_7.		; Device Check
 DEFSYM %H3WHD==1_6.		; Index Unsafe (Bad %HMWHD)
 DEFSYM %H3DCL==1_5.		; DC Low voltage
 DEFSYM %H3SDF==1_4.		; Serdes Data (data buffer timing) Failure
 DEFSYM %H3PAR==1_3.		; Data Parity Error during write operation
 DEFSYM %H3SYB==1_2.		; Sync Byte error
 DEFSYM %H3SYC==1_1.		; Sync Clock failure
 DEFSYM %H3RTM==1_0.		; Run timeout

];RP07P

IFN RM03P\RM80P,[
; RM has no Current Cylinder Register, the Error 2 Register is
; in a different place with different bits, and there is no 
; Error 3 register

DEFSYM	%HRER2=:776742		;ERROR 2.
 DEFSYM %H2BSE==1_15.		; Bad Sector (sector marked bad on disk)
 DEFSYM	%H2SKI==1_14.		; Seek Incomplete (also sets UNS+ATA+PIP+RDY)
 DEFSYM %H2OPE==1_13.		; Drive address plug was removed
 DEFSYM %H2IVC==1_12.		; Invalid Command (really drive not valid)
 DEFSYM %H2LSC==1_11.		; LSC Sucks
 DEFSYM %H2LBC==1_10.		; Loss of Bitcheck (hardware lossage)
 DEFSYM %H2DVC==1_7		; Device Check (generic hardware lossage)
 DEFSYM %H2SSE==1_5		; Skip Sector found (can't happen in 18bit)
 DEFSYM %H2DPE==1_3		; Data Parity Error in controller

];RM03P\RM80P

DEFSYM	%HRPOS=:776744		;ECC POSITION.

DEFSYM	%HRPAT=:776746		;ECC PATTERN.

IFN $$TEMP,EXPUNG DEFSYM
